package com.laiyima.zhongjiang.linghuilv.demo.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.laiyima.zhongjiang.linghuilv.demo.R;
import com.laiyima.zhongjiang.linghuilv.demo.Serviceprovider.BanlanceDetActivity;
import com.laiyima.zhongjiang.linghuilv.demo.bean.BalanceChildBean;

import java.text.DecimalFormat;
import java.util.List;

public class BalanceChildAdapter extends BaseAdapter {
    private Context mContext;
    private LayoutInflater mInflater;
    BalanceAdapter adapter;
    private List<BalanceChildBean> mBalanceChildBean;
    private String TAG="AgentAdapter";

    public BalanceChildAdapter(BanlanceDetActivity context, List<BalanceChildBean> list, BalanceAdapter adapter) {
        this.mInflater = LayoutInflater.from(context);
        this.mBalanceChildBean = list;
        this.adapter = adapter;
        this.mContext = context;

    }

    @Override
    public int getCount() {
        return mBalanceChildBean.size();
    }

    @Override
    public Object getItem(int position) {
        return mBalanceChildBean.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null){
            convertView = mInflater.inflate(R.layout.balancechild_item,null);
            viewHolder = new ViewHolder();
            viewHolder.balance_desc = convertView.findViewById(R.id.balance_desc);
            viewHolder.balance_money = convertView.findViewById(R.id.balance_money);
            viewHolder.balance_create_time = convertView.findViewById(R.id.balance_create_time);
            viewHolder.balance_state = convertView.findViewById(R.id.balance_state);
            viewHolder.balance_fee = convertView.findViewById(R.id.balance_fee);
            viewHolder.balance_id = convertView.findViewById(R.id.balance_id);
            viewHolder.balance_uid = convertView.findViewById(R.id.balance_uid);
            convertView.setTag(viewHolder);

        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        BalanceChildBean transactiondetailsBean = mBalanceChildBean.get(position);
        viewHolder.balance_desc.setText(transactiondetailsBean.getDesc());
        Double a1 = Double.parseDouble(transactiondetailsBean.getMoney());
        DecimalFormat decimalFormatq = new DecimalFormat("0.00");
        String b1 = decimalFormatq.format(a1);
        viewHolder.balance_money.setText(b1+"元");
        String time=transactiondetailsBean.getCreate_time();
         String yue=time.substring(5,7);
        String ri=time.substring(8,10);
        String shi=time.substring(11,16);
        viewHolder.balance_create_time.setText(yue+"月"+ri+"日"+shi);
        viewHolder.balance_state.setText(transactiondetailsBean.getState());
       if(transactiondetailsBean.getState().equals("提现失败")){
           viewHolder.balance_state.setTextColor(Color.parseColor("#F0562E"));
       }else {
           viewHolder.balance_state.setTextColor(Color.parseColor("#126AE4"));
       }
        viewHolder.balance_fee.setText(transactiondetailsBean.getFee());
        viewHolder.balance_id.setText(transactiondetailsBean.getId());
        viewHolder.balance_uid.setText(transactiondetailsBean.getUid());
        return convertView;
    }
    public static class ViewHolder{
        TextView balance_desc;
        TextView balance_money;
        TextView balance_create_time;
        TextView balance_state;
        TextView balance_fee;
        TextView balance_id;
        TextView balance_uid;
    }
}
